﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConceptionLogiciel_Devoir1
{
    class CatalogueClient
    {
        private static CatalogueClient _instance;
        static readonly object instanceLock = new object();

        private Dictionary<String, Client> mapClient;

        // Constructor
        // -------------------------------------------------------------------------------
        private CatalogueClient() 
        {
            this.mapClient = new Dictionary<String, Client>();
            // params Client: noCarteCredit, solde
            mapClient.Add("PERMIS0004", new Client("Blan", "Sim", "819-789-5555", "352 Houle", "PERMIS0004", 12345, 1.25));
            mapClient.Add("PERMIS0012", new Client("Sim", "Anna", "789-522-6321", "345 Rivet", "PERMIS0012", 96587, 2.25));
            mapClient.Add("PERMIS1010", new Client("Beaumier", "Laurence", "526-741-5255", "987 Centre", "PERMIS1010", 3458, 4.08));
            mapClient.Add("PERMIS1018", new Client("Dargis", "Mathieu", "585-741-0027", "789 ave Hall", "PERMIS1018", 963, 100));
        }

        // Retourne l'intance du catalogue de client (pattern singleton)
        // -------------------------------------------------------------------------------
        public static CatalogueClient getInstance()
        {
            lock (instanceLock)
            {
                if (_instance == null)
                    _instance = new CatalogueClient();

                return _instance;
            }
        }

        // Ajouter un client
        // -------------------------------------------------------------------------------
        public void ajouterClient(String _noPermisConduire,Client _client)
        {
            mapClient.Add(_noPermisConduire, _client);
        }

        // Retourne le client
        // -------------------------------------------------------------------------------
        public Client getClient(String _noPermisConduire)
        {
            return (Client) mapClient[_noPermisConduire];
        }

        // Retourne la map en entier
        // -------------------------------------------------------------------------------
        public Dictionary<String, Client> getCatalogueClient()
        {
            return mapClient;
        }

        // Retourner un nouveau numero de location unique pour la key de la map de 
        // sessionLocation et le idLocation
        // -------------------------------------------------------------------------------
        public int getNewLocationNumber()
        {
            int currId = -1;

            foreach (KeyValuePair<String, Client> c in mapClient)
            {
                if (c.Value.getBiggestLocationId() > currId)
                    currId = c.Value.getBiggestLocationId();
            }

            if (currId == -1)
                currId = 1;
            else
                currId++;

            return currId;
        }

    }
}
